<?php
namespace WebAdmin\Controller;
use WebAdmin\Controller\BaseController;
class UsersController extends BaseController {
	
    public function index(){
    	$this->assign('page_title','会员列表');
//    	$userModel = D("Users");
//    	$list = $userModel->select();
//    	$this->assign('list',$list);
    	$this->display();
    }

    public function getData()
    {
        $DataModel = D("Users");
        $items = array();
        $page = (int)$_GET['page'];
        $items['page'] = $page>0 ? $page :1;
        $items['records'] = $DataModel->count();
        $limit = $_GET['rows'] ? (int)$_GET['rows']: 20;
        $items['total'] = ceil($items['records']/$limit);
        $list = $DataModel->page($page)->limit($limit)->select();
        $items['rows'] = $list;


        $this->ajaxReturn( $items);
    }

    public function add(){

        $PositionModel = D("Users");

        echo "<script>window.location.href='".__APP__."/index.php/Users/';</script>";exit;
        $this->display();

    }

    public function edit(){
        $DataModel = D("Users");

        if(!empty($_POST)) {

            $DataModel->create();

            $DataModel->where("id=".(int)$_POST['id'])->save($_POST);

            header("Content-type: text/html; charset=utf-8");
            echo "<script>window.location.href='".__APP__."/index.php/Users/';</script>";exit;
            }else{

              $item = $DataModel->where("id=".(int)$_GET['id'])->select();

            $this->assign('vo',$item[0]);
        }

        $this->display();

    }

    public function delete(){
        if(!empty($_POST)) {
            $DataModel = D("Users");
            $id = $_POST['id'];
            $result = $DataModel->delete((int)$id);

            if($result){
                header("Content-type: text/html; charset=utf-8");
                echo "<script>layer.closeAll(); \$table.trigger(\"reloadGrid\");</script>";exit;
            }
        }     $this->display();
    }
    
}